package com.yuan.yblog.portal.controller;

import com.yuan.yblog.common.api.CommonResult;
import com.yuan.yblog.crud.entity.Category;
import com.yuan.yblog.portal.aop.annotation.SlidingWindowLimiter;
import com.yuan.yblog.portal.enums.LimitType;
import com.yuan.yblog.portal.service.CategoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.io.Serializable;
import java.util.List;

/**
 * (Category)表控制层
 * @since 2023-12-03 14:21:12
 */
@RestController
@RequestMapping("/category")
@Tag(name = "文章分类（category）接口")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @SlidingWindowLimiter(key = "category", windowSize = 120, windowTimeRange = 60, limitType = LimitType.IP)
    @GetMapping("/listAll")
    @Operation(summary = "获取所有文章类型")
    public CommonResult<List<Category>> selectAll() {
        List<Category> result = categoryService.listAll();
        return CommonResult.success(result);
    }

    @SlidingWindowLimiter(key = "category", windowSize = 120, windowTimeRange = 60, limitType = LimitType.IP)
    @GetMapping("/{id}")
    @Operation(summary = "根据id，获取分类信息")
    public CommonResult<Category> selectOne(@Parameter(description = "分类id") @PathVariable Long id) {
        Category category = categoryService.selectOne(id);
        return CommonResult.success(category);
    }

}

